package com.fz.us.admin.company.dao.impl;

import com.fz.us.admin.base.bean.BaseEnumManager;
import com.fz.us.admin.base.dao.impl.BaseDaoImpl;
import com.fz.us.admin.company.dao.StepBriefDao;
import com.fz.us.admin.company.entity.CommonConfig;
import com.fz.us.admin.company.entity.ProcessBrief;
import com.fz.us.admin.company.entity.StepBrief;

import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import java.util.List;

/**
 * Created by ZhuChunXiao on 2017/4/26.
 */
@Repository
public class StepBriefDaoImpl extends BaseDaoImpl<StepBrief, String> implements StepBriefDao {

    @Override
    public StepBrief getInfoByStepNo(ProcessBrief processBrief, int stepNo) {
        Assert.notNull(processBrief, "processBrief is required");
        Assert.notNull(stepNo, "stepNo is required");
        String hql = "from StepBrief where processBrief=:processBrief and stepNo=:stepNo and state=:state";
        List<StepBrief> stepBriefList = getSession().createQuery(hql).setParameter("processBrief", processBrief)
                .setParameter("stepNo",stepNo).setParameter("state", BaseEnumManager.StateEnum.Enable).list();
        if(stepBriefList != null && stepBriefList.size()>0){
            return stepBriefList.get(0);
        }
        return null;
    }

    @Override
    public StepBrief getInfoByCommonConfig(CommonConfig commonConfig) {
        Assert.notNull(commonConfig, "commonConfig is required");
        String hql = "from StepBrief where commonConfig =:commonConfig and state=:state";
        List<StepBrief> stepBriefList = getSession().createQuery(hql).setParameter("commonConfig", commonConfig)
                .setParameter("state", BaseEnumManager.StateEnum.Enable).list();
        if(stepBriefList != null && stepBriefList.size()>0){
            return stepBriefList.get(0);
        }
        return null;
    }
}
